package cn.lingyangwl.agile.system.handler.config;

import cn.lingyangwl.agile.common.core.config.GlobalProperties;
import cn.lingyangwl.agile.infra.InfraApi;
import cn.lingyangwl.agile.model.constants.ServiceCodeCons;
import cn.lingyangwl.agile.model.enums.ConfigKeyEnum;
import cn.lingyangwl.agile.model.module.config.param.BaseConfigParam;
import cn.lingyangwl.agile.model.module.config.param.WxCpParam;
import cn.lingyangwl.agile.model.module.tenant.TenantContext;
import cn.lingyangwl.agile.system.model.entity.SysConfig;
import cn.lingyangwl.framework.tool.core.UrlUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author shenguangyang
 */
@Component
public class WxCpConfigHandler extends ConfigHandler {
    @Resource
    private InfraApi infraApi;
    @Resource
    private GlobalProperties properties;

    @Override
    public void doneWriteOps(SysConfig newConfig, BaseConfigParam<?> param) {
        WxCpParam wxCpParam = (WxCpParam) param;

    }

    @Override
    protected BaseConfigParam<?> doneReadOps(BaseConfigParam<?> param) {
        WxCpParam wxCpParam = (WxCpParam) param;
        wxCpParam = Optional.ofNullable(wxCpParam).orElse(new WxCpParam());
        String tenantId = TenantContext.get().getTenantId();
        wxCpParam.setMsgPushUrl(UrlUtils.removeRepeatSlashOfUrl(properties.getServerAddr() + "/" + ServiceCodeCons.INFRA_SERVICE + "/open/wxCp/" + tenantId));
        return wxCpParam;
    }

    @Override
    public ConfigKeyEnum configKey() {
        return ConfigKeyEnum.WX_CP;
    }
}
